package com.example.springboot_sp.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.example.springboot_sp.common.Result;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.example.springboot_sp.service.ICourseService;
import com.example.springboot_sp.entity.Course;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 郭守军
 * @since 2022-09-02
 */
@RestController
@RequestMapping("/course")
        public class CourseController {
    
        @Resource
        private ICourseService courseService;

        // 新增或者更新
        @PostMapping
        public Result save(@RequestBody Course course) {
                return Result.success(courseService.saveOrUpdate(course));
                }

        @DeleteMapping("/{id}")
        public Result delete(@PathVariable Integer id) {
                return Result.success(courseService.removeById(id));
                }

        @PostMapping("/del/batch")
        public Result deleteBatch(@RequestBody List<Integer> ids) {
                return Result.success(courseService.removeByIds(ids));
                }

        @GetMapping
        public Result findAll() {
                return Result.success(courseService.list());
                }

        @GetMapping("/{id}")
        public Result findOne(@PathVariable Integer id) {
                return Result.success(courseService.getById(id));
                }

        @GetMapping("/page")
        public Result findPage(@RequestParam String name,
                               @RequestParam Integer pageNum,
                               @RequestParam Integer pageSize) {
                Page<Course> page = courseService.findPage(new Page<>(pageNum, pageSize), name);
                return Result.success(page);}
}

